import datetime
import multiprocessing
from util import *
import copy
from CloudSystem import run_once



def generate_default_args():
    args=Args()
    args.pre_request_num=10000
    args.request_num=10000
    args.out_dir="output_size2"
    args.time_expand=1
    
    return args


def run_once_this(method, call_graph_size_min, call_graph_size_max,spec_reliability):
    print(f"start once {method}, {call_graph_size_min}, {call_graph_size_max}")
    args=generate_default_args()
    args.spec_reliability=spec_reliability
    args.deploy_schedule_strategy=method
    args.call_graph_size_min=call_graph_size_min
    args.call_graph_size_max=call_graph_size_max
    args.trace_id=-1
    
    args_copy=copy.deepcopy(args)
    run_once(args_copy)
    print(f"End once {method}, {call_graph_size_min}, {call_graph_size_max}")
    
    



task_args_list=[]
for spec_reliability in [0.99, 0.9999]:
    for call_size_min in [0,10,20,30,40]:
        for method in ["ours", "RR","C_GM", "GSMS","QFEC","R_RIR"]: #"ours", "RR","C_GM", "GSMS","QFEC","R_RIR"
        
            task_args_list.append((method, call_size_min, call_size_min+10, spec_reliability))
        
                

with multiprocessing.Pool(processes=15) as pool:
        #   starmap 直接开始所有的
        #   apply_async 一个一个参数放入执行
        
        interval=0
        results=[]
        index=0
        while index<len(task_args_list):
            # length=min(batch_size, len(task_args_list)-index )
            result=pool.apply_async(run_once_this, task_args_list[index])
            results.append(result)
            time.sleep(interval)
            index+=1
            
        for result in results:
            result.get()


    
print("End all sub threadings")
